//  User.js
const mongoose = require("mongoose");
const transDatePlugin = require("../../plugins/transDatePlugin");
const IdsPlugin = require("../../plugins/IdsPlugin");
const Schema = mongoose.Schema;

const MenuSchema = new Schema(
	{
		id: {
			type: Number,
			required: true, //是否必需
			unique: true, //字段唯一性
			default: 1,
		},
		pid: {
			type: String,
		},
		title: {
			type: String,
			required: true,
		},
		type: {
			type: String,
			required: true, //是否必需
		},
		name: {
			type: String,
		},
		icon: {
			type: String,
		},
		path: {
			type: String,
		},
		desc: {
			type: String,
		},
		sort: {
			type: Number,
			default: 0,
		},
		is_show: {
			type: Boolean,
		},
		is_delete: {
			type: Boolean,
			default: false,
		},
		create_time: {
			type: String,
			required: true,
			default: Date.now,
		},
		update_time: {
			type: String,
		},
		status: {
			type: String,
			default: "1",
		},
	},
	{
		versionKey: false,
		timestamps: { createdAt: "create_time", updatedAt: "update_time" },
	}
);

MenuSchema.plugin(transDatePlugin, { paths: ["update_time"] });
MenuSchema.plugin(IdsPlugin, "menu");
module.exports = Menu = mongoose.model(
	"menu",
	MenuSchema,
	`${process.env.PREFIX}_menu`
);
